from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer

class FeatureEngineer:
    @staticmethod
    def preprocess(df: pd.DataFrame) -> pd.DataFrame:
        """自动化数据预处理"""
        # 处理缺失值
        num_imputer = SimpleImputer(strategy="median")
        cat_imputer = SimpleImputer(strategy="most_frequent")
        num_cols = df.select_dtypes(include='number').columns
        cat_cols = df.select_dtypes(include='object').columns
        
        df[num_cols] = num_imputer.fit_transform(df[num_cols])
        df[cat_cols] = cat_imputer.fit_transform(df[cat_cols])
        
        # 数值型标准化
        scaler = StandardScaler()
        df[num_cols] = scaler.fit_transform(df[num_cols])
        return df